  const state = {
    fileName: '',
    menuVisible: false,
    // 底部的菜单项，倒数第二条，-1：不显示，0：字号，1：主题、2：进度条、3：目录
    settingVisible: -1,
    defaultFontSize: 16,
    currentBook: null,
    defaultFontFamily: 'Merriweather',
    fontFamilyVisible: false,
    defaultTheme: 'Default',
    // 图示是否加载完毕
    bookAvailable: false,
    // 阅读进度，百分比
    progress: 0,
    // 章节数，第几章
    section: 0,
    isPaginating: true,
    navigation: null,
    cover: null,
    // 书籍的基本信息，作者，title等obj
    metadata: null,
    // 当前页/总页数
    paginate: '',
    pagelist: null,
    offsetY: 0,
    isBookmark: null
  }
  const mutations = {
    SET_FILENAME: (state, fileName) => {
      state.fileName = fileName
    },
    SET_MENU_VISIBLE: (state, visible) => {
      state.menuVisible = visible
    },
    SET_SETTING_VISIBLE: (state, visible) => {
      state.settingVisible = visible
    },
    SET_DEFAULT_FONT_SIZE: (state, fontSize) => {
      state.defaultFontSize = fontSize
    },
    SET_DEFAULT_FONT_FAMILY: (state, font) => {
      state.defaultFontFamily = font
    },
    SET_FONT_FAMILY_VISIBLE: (state, visible) => {
      state.fontFamilyVisible = visible
    },
    SET_DEFAULT_THEME: (state, theme) => {
      state.defaultTheme = theme
    },
    SET_BOOK_AVAILABLE: (state, bookAvailable) => {
      state.bookAvailable = bookAvailable
    },
    SET_PROGRESS: (state, progress) => {
      state.progress = progress
    },
    SET_SECTION: (state, section) => {
      state.section = section
    },
    SET_IS_PAGINATING: (state, isPaginating) => {
      state.isPaginating = isPaginating
    },
    SET_CURRENT_BOOK: (state, currentBook) => {
      state.currentBook = currentBook
    },
    SET_NAVIGATION: (state, navigation) => {
      state.navigation = navigation
    },
    SET_COVER: (state, cover) => {
      state.cover = cover
    },
    SET_METADATA: (state, metadata) => {
      state.metadata = metadata
    },
    SET_PAGINATE: (state, paginate) => {
      state.paginate = paginate
    },
    SET_PAGELIST: (state, pagelist) => {
      state.pagelist = pagelist
    },
    SET_OFFSETY: (state, offsetY) => {
      state.offsetY = offsetY
    },
    SET_IS_BOOKMARK: (state, isBookmark) => {
      state.isBookmark = isBookmark
    },
    TOGGLE_MENU: (state) => {
      state.menuVisible = !state.menuVisible
    }
  }

  const actions = {
    // book部分
    setFontFamilyVisible: ({
      commit
    }, visible) => {
      return commit('SET_FONT_FAMILY_VISIBLE', visible)
    },
    setDefaultFontFamily: ({
      commit
    }, font) => {
      return commit('SET_DEFAULT_FONT_FAMILY', font)
    },
    setDefaultFontSize: ({
      commit
    }, fontSize) => {
      return commit('SET_DEFAULT_FONT_SIZE', fontSize)
    },
    setSettingVisible: ({
      commit
    }, visible) => {
      return commit('SET_SETTING_VISIBLE', visible)
    },
    setMenuVisible: ({
      commit
    }, visible) => {
      return commit('SET_MENU_VISIBLE', visible)
    },
    setFileName: ({
      commit
    }, fileName) => {
      return commit('SET_FILENAME', fileName)
    },
    setDefaultTheme: ({
      commit
    }, theme) => {
      return commit('SET_DEFAULT_THEME', theme)
    },
    setBookAvailable: ({
      commit
    }, bookAvailable) => {
      return commit('SET_BOOK_AVAILABLE', bookAvailable)
    },
    setProgress: ({
      commit
    }, progress) => {
      return commit('SET_PROGRESS', progress)
    },
    setSection: ({
      commit
    }, section) => {
      return commit('SET_SECTION', section)
    },
    setIsPaginating: ({
      commit
    }, isPaginating) => {
      return commit('SET_IS_PAGINATING', isPaginating)
    },
    setCurrentBook: ({
      commit
    }, book) => {
      return commit('SET_CURRENT_BOOK', book)
    },
    setNavigation: ({
      commit
    }, navigation) => {
      return commit('SET_NAVIGATION', navigation)
    },
    setCover: ({
      commit
    }, cover) => {
      return commit('SET_COVER', cover)
    },
    setMetadata: ({
      commit
    }, metadata) => {
      return commit('SET_METADATA', metadata)
    },
    setPaginate: ({
      commit
    }, paginate) => {
      return commit('SET_PAGINATE', paginate)
    },
    setPagelist: ({
      commit
    }, pagelist) => {
      return commit('SET_PAGELIST', pagelist)
    },
    setIsBookmark({
      commit
    }, isBookmark) {
      return commit('SET_IS_BOOKMARK', isBookmark)
    },
    setOffsetY({
      commit
    }, offsetY) {
      return commit('SET_OFFSETY', offsetY)
    },
    toggleMenu({
      commit
    }) {
      console.log('控制菜单');
      return commit('TOGGLE_MENU')
    },
  }


  export default {
    namespaced: true,
    state,
    mutations,
    actions,
  }